var t = getApp(), e = require("../../utils/util.js"), a = null, i = !1, n = wx.createInnerAudioContext();

n.src = "/voice/1.mp3", Page({
    data: {
        StatusBar: t.globalData.StatusBar,
        CustomBar: t.globalData.CustomBar,
        shaking: !1,
        allowShaking: !0,
        status: {
            voice: !1,
            point: 1,
            accelerometer: !0,
            text: [ "国外游", "国内游", "省内游", "市内游", "梦游", "加班" ],
            defineCurIndex: 5
        },
        defineText: [ {
            title: "标准骰子",
            text: [ "1", "2", "3", "4", "5", "6" ],
            type: 1
        }, {
            title: "犯错惩罚",
            text: [ "跪榴莲", "跪搓衣板", "跪键盘", "跪方便面", "跪酒瓶", "跪遥控器" ],
            type: 2
        }, {
            title: "游戏惩罚",
            text: [ "真心话", "唱歌跳舞", "上下蹲", "告白", "表情帝", "撒娇" ],
            type: 2
        }, {
            title: "家务活",
            text: [ "买菜", "做饭", "洗碗", "擦地", "洗衣", "呆着" ],
            type: 2
        }, {
            title: "大扫除",
            text: [ "扫地拖地", "卫生间", "擦门窗", "厨房", "阳台", "桌椅" ],
            type: 2
        }, {
            title: "节假日",
            text: [ "国外游", "国内游", "省内游", "市内游", "梦游", "加班" ],
            type: 2
        }, {
            title: "今天吃啥",
            text: [ "火锅", "烧烤", "烤鱼", "猪脚饭", "木桶饭", "炒米粉" ],
            type: 2
        }, {
            title: "运动",
            text: [ "游泳", "羽毛球", "篮球", "跑步", "爬山", "骑行" ],
            type: 2
        } ],
        sharing: !1,
        canUserSetVip: !1
    },
    onShareAppMessage: function(t) {
        var e = this.data.status.defineCurIndex;
        if (e > 0) {
            this.setData({
                sharing: !0
            });
            var a = this.data.defineText[e].text.join("、");
            return {
                title: this.data.defineText[e].title + "摇骰子(摇色子)，" + a
            };
        }
        return {
            title: "家务活摇骰子(摇色子)，跪榴莲、跪搓衣板、跪键盘、跪方便面、跪酒瓶、跪遥控器",
            imageUrl: "https://wx3.sinaimg.cn/mw690/77d4598fly1g6mqmguta6j20ae08k769.jpg"
        };
    },
    interstitialAdShow: function() {
        a && "function" == typeof a.show && this.canPageShowAd() && a.show().catch(function(t) {
            console.info(t);
        });
    },
    canPageShowAd: function() {
        try {
            var t = wx.getStorageSync("interstitialAdCache-lucky");
            return "" == t || (Date.parse(new Date()) - t.time) / 1e3 > 3600;
        } catch (t) {}
        return !1;
    },
    onLoad: function() {
        wx.createInterstitialAd && this.canPageShowAd() && ((a = wx.createInterstitialAd({
            adUnitId: t.ad.cpAd_02
        })).onLoad(function() {}), a.onError(function(t) {}), a.onClose(function() {
            wx.setStorageSync("interstitialAdCache-lucky", {
                time: Date.parse(new Date())
            });
        }));
    },
    onHide: function() {
        i = !1, wx.stopAccelerometer(), wx.setStorageSync("textStatus", this.data.status);
    },
    onUnload: function() {
        i = !1, wx.stopAccelerometer();
    },
    onShow: function() {
        this.setData({
            sharing: !1
        }), i = !0, "function" == typeof this.getTabBar && this.getTabBar() && this.getTabBar().setData({
            selected: 2
        });
        var t = wx.getStorageSync("textStatus");
        t && this.setData({
            status: t
        }), this.canUserSetVipHandle(), this.interstitialAdShow(), this.data.status.accelerometer && this.accelerometer();
    },
    accelerometer: function() {
        var t = this;
        wx.onAccelerometerChange(function(e) {
            !t.data.shaking && i && Math.abs(e.x) > .8 && Math.abs(e.y) > .8 && Math.abs(e.z) > .8 && (t.change(), 
            wx.vibrateLong());
        });
    },
    canUserSetVipHandle: function() {
        var t = wx.getStorageSync("canUserSetVip");
        "" != t && (Date.parse(new Date()) - t.time) / 1e3 < 43200 && this.setData({
            canUserSetVip: !0
        });
    },
    defineTextChange: function(t) {
        var e = t.currentTarget.dataset.index;
        this.setData({
            "status.text": this.data.defineText[e].text,
            "status.defineCurIndex": e
        });
    },
    setText: function(t) {
        var e = t.currentTarget.dataset.index, a = JSON.parse(JSON.stringify(this.data.defineText[e])).text;
        this.setData({
            "defineText[0].text": a,
            "status.text": a
        });
    },
    allow: function() {
        this.data.shaking || this.setData({
            allowShaking: !this.data.allowShaking
        });
    },
    change: function(t) {
        if (!this.data.shaking && this.data.allowShaking) {
            var e = this;
            e.setData({
                shaking: !0
            }), e.data.status.voice && (n.startTime = 0, n.play()), setTimeout(function() {
                n.stop(), e.setData({
                    "status.point": Math.floor(6 * Math.random()) + 1,
                    shaking: !1
                }), e.interstitialAdShow();
            }, 2e3);
        }
    },
    voiceChange: function(t) {
        this.setData({
            "status.voice": !this.data.status.voice
        });
    },
    accelerometerChange: function(t) {
        this.setData({
            "status.accelerometer": !this.data.status.accelerometer
        }), this.data.status.accelerometer ? this.accelerometer() : wx.stopAccelerometer(), 
        wx.setStorageSync("textStatus", this.data.status);
    },
    hideModal: function(t) {
        this.setData({
            modalName: null
        });
    },
    curTextInput: function(t) {
        var e = this.data.status.text;
        e[t.currentTarget.dataset.index] = t.detail.value, this.setData({
            "status.text": e
        });
    },
    adShow: function(t) {
        videoAd && videoAd.show().catch(function() {
            videoAd.load().then(function() {
                return videoAd.show();
            }).catch(function(t) {
                e.videoAdErrCodeHandle(t);
            });
        });
    },
    catchtap: function() {}
});